import {
    orderList,
    removeOrder,
    orderReceive,
    sendSiteMsg,
    cancleOrder,
    buyAgain
} from "api/order";
import pay from 'service/pay';

const order = {
    data() {
        return {

        }
    },
    methods: {
        //货到付款的取消订单  --单纯提示
        cancelmoneyFor(status) {
            this.$dialog.alert({
                title: '提示',
                message: status == 2 ? '卖家可能已经接单配货， 您需要联系客服申请取消订单哦' : '卖家已经发货了，您需要联系客服协商取消订单哦。'
            }).then(() => {
                // on close
            });
        },
        //确认收货
        confirmGoods(subNumber) {
            this.$dialog.confirm({
                title: '确认收货',
                message: '您确定要收货?PS:请务必要收到货后在执行此操作!'
            }).then(() => {
                // on confirm
                orderReceive({
                    subNumber: subNumber
                }).then(res => {
                    if (res.status == 1) {
                        this.$toast('收货成功!')
                        setTimeout(() => {
                            this.refreshPage()
                        }, 1000)
                    } else {
                        this.$toast(res.msg);
                    }
                })
            }).catch(() => {
                // on cancel
            });
        },
        //查看物流
        checkLogistical(subNumber,reciverMobile) {
            this.$router.push({
                path: `/logistics`,
                query: {
                    subNumber,
                    reciverMobile
                }
            });
        },
        //提醒发货
        remindDelivery(subNumber) {
            this.$utils.uDebounce(() => {
				sendSiteMsg({
				    subNumber: subNumber
				}).then(res => {
				    if (res.status == 1) {
				        this.$toast('提醒成功，商家正在尽快处理')
				    } else {
				        this.$toast(res.msg)
				    }
				})
			})
        },
        //删除订单
        deleteOrder(subNumber, flag) {
            let that = this
            this.$dialog.confirm({
                title: '删除订单',
                message: '你确认是否删除改订单'
            }).then(() => {
                // on confirm
                removeOrder({
                    subNumber: subNumber
                }).then(res => {
                    if (res.status == 1) {
                        this.$toast({
                            message: '删除订单成功',
                            duration: 1000
                        });
                        setTimeout(() => {
                            this.refreshPage()
                            if (flag == false) {
                                this.goback()
                            }
                        }, 1500)
                    } else {
                        this.$toast(res.msg);
                    }
                })
            }).catch(() => {
                // on cancel
            });
        },
        
        // 立即付款
        payment(subNumber) {
            this.$utils.uDebounce(() => {
				pay.orderPay(subNumber);
			})
        },

        //再次购买
        goBuy(subNumber) {
			this.$utils.uDebounce(() => {
				let changeStr
				buyAgain({
				    subNumber: subNumber
				}).then(res => {
				    if (res.status == 1) {
				
				        this.$router.push({
				            path: `/cart`,
				            query: {
				                shopCartItems: res.result,
				                type: 'NORMAL',
				                buyNow: true
				            }
				        });
				
				    } else {
				        this.$toast(res.msg)
				    }
				})
			})
            
        },
        //取消订单
        cancelOrder(subNumber) {
            this.subNumber = subNumber
            this.$dialog.confirm({
                title: '是否取消订单',
                message: '您确定要取消本次交易'
            }).then(() => {
                // on confirm
                cancleOrder({
                    subNumber: subNumber
                }).then(res => {
                    if (res.status == 1) {
                        this.$toast('取消成功!')
                        setTimeout(() => {
                            this.refreshPage()
                        }, 1000)
                    } else {
                        this.$toast(res.msg);
                    }
                })
            }).catch(() => {
                // on cancel
            });
        },
        //确认收货
        confirmGoods(subNumber) {
            this.$dialog.confirm({
                title: '确认收货',
                message: '您确定要收货?PS:请务必要收到货后在执行此操作!'
            }).then(() => {
                // on confirm
                orderReceive({
                    subNumber: subNumber
                }).then(res => {
                    if (res.status == 1) {
                        this.$toast('收货成功!')
                        setTimeout(() => {
                            this.refreshPage()
                        }, 1000)
                    } else {
                        this.$toast(res.msg);
                    }
                })
            }).catch(() => {
                // on cancel
            });
        },
        //查看拼团详细
        gofightgroupDet(addNumber) {
            this.$router.push({
                path: `/fightgroupDetail`,
                query: {
                    sn: addNumber,
                    source: 'GROUP'
                }
            });
        },
    
    },
}


export default order